﻿using FarseerPhysics;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Syngine;
using Syngine.Physics;
using Syngine.Physics.Components;

namespace BenchMark.ShootingGame
{
	public class BlueBox : DrawableSprite
	{
		public BlueBox(float? width, float? height) : this(Color.White)
		{
			Width = width;
			Height = height;
		}

		public BlueBox(Color color)
		{
			Color = color;
		}

		public float? Width { get; set; }

		public float? Height { get; set; }

		//protected override void UpdateCore(UpdateContext context)
		//{
		//	//var state = Mouse.GetState();

		//	//if (state.LeftButton == ButtonState.Pressed)
		//	//{
		//	//	// Convert the touch position (screen coords) to world coords.
		//	//	Vector2 worldTouchPosition = ConvertUnits.ToSimUnits(new Vector2(state.X, state.Y));

		//	//	// Get the direction the force should be applied.
		//	//	Vector2 direction = Vector2.Normalize(Body.Position - worldTouchPosition);

		//	//	// Get the distance between the body and touch positions.
		//	//	float distance = Vector2.Distance(Body.Position, worldTouchPosition);

		//	//	// Get the force.  Deminishes the larger the distance.
		//	//	Vector2 force = ((_forceConstant * direction) / distance);

		//	//	// Apply the force to the body.
		//	//	Body.ApplyForce(force);
		//	//}
		//	base.UpdateCore(context);
		//}

		public override void LoadContent(LoadContext context)
		{
			base.LoadContent(context);

			Bounds = new Rectangle(0, 0, (int)(Width ?? Texture.Width()), (int)(Height ?? Texture.Height()));
			SourceRectangle = new Rectangle(0, 0, (int)(Width ?? Texture.Width()), (int)(Height ?? Texture.Height()));
			Body = BodyFactory.CreateRectangle(WorldContext.World, (Width ?? Texture.Width()).ToSimUnits(), (Height ?? Texture.Height()).ToSimUnits(), 0.1f);
			Body.BodyType = BodyType.Dynamic;
			Body.Restitution = 0.8f;
			Body.Mass = 0.9f;
		}

		protected override Texture2D GetAsset(LoadContext context)
		{
			return context.Content.Load<Texture2D>("WhiteSquare");
		}

		public override void UnloadContent()
		{
		}
	}
}